package com.cac.demo.controller.receivedDeliveryPlan;

import com.alibaba.fastjson.JSON;
import com.cac.demo.service.receivedDeliveryPlan.ReceivedDeliveryPlanService;
import com.cac.demo.util.adapter.PageParameter;
import com.cac.demo.util.adapter.QueryReqBean;
import com.cac.demo.util.adapter.QueryRespBean;
import com.cac.demo.util.adapter.ResponseMsg;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

/**
 * @className: ReceivedDeliveryPlanRest
 * @description: （描述这个类的作用）
 * @author: lqc
 * @date: 2023/5/18 15:47:47 周四
 * @version: 1.0
 */
@RestController
@RequestMapping("/ReceivedDeliveryPlan")
@Slf4j
public class ReceivedDeliveryPlanRest {

    @Autowired
    private ReceivedDeliveryPlanService receivedDeliveryPlanService;

    //查询已叫箱子交接单
    @PostMapping("/searchDeliveryReceived")
    public ResponseMsg searchDeliveryReceived(@RequestBody HashMap map) {
        ResponseMsg<QueryRespBean<HashMap>> responseMsg = new ResponseMsg<>();
//        String receiveDate = JSON.toJSONString(map.get("receiveTime"));
//        String endTimeParams = JSON.toJSONString(map.get("endDate"));
//        Date receiveTime = JSON.parseObject(receiveDate, Date.class);
        String page = JSON.toJSONString(map.get("pageParameter"));
        HashMap pageMap = JSON.parseObject(page, HashMap.class);
        PageParameter pageParameter = JSON.parseObject(page, PageParameter.class);
     //   PageParameter pageParameter = new PageParameter(Integer.parseInt(pageMap.get("currentPage").toString()),Integer.parseInt(pageMap.get("pageSize").toString()));
        String DTO = JSON.toJSONString(map.get("searchParams"));
        HashMap searchParams = JSON.parseObject(DTO, HashMap.class);
        QueryReqBean<HashMap> queryReqBean = new QueryReqBean<>();
        queryReqBean.setPageParameter(pageParameter);
        queryReqBean.setSearchParams(searchParams);
        QueryRespBean<HashMap> result = receivedDeliveryPlanService.searchDeliveryReceived(queryReqBean);
        responseMsg.setResponseBody(result);
        return responseMsg;
    }

    //查询分配缓存箱及数量
    @PostMapping("/searchReceDetail")
    public List<HashMap> searchReceDetail(@RequestBody HashMap map){
        return receivedDeliveryPlanService.searchReceDetail(map);
    }
}
